package com.li.net;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;

public class SocketThread  implements Runnable{

	private Socket socket;
	public SocketThread(Socket socket){
		this.socket=socket;
	}
	public void run() {
		InputStream is;
		try {
			is = socket.getInputStream();
			InputStreamReader ir=new InputStreamReader(is);
			char[] a=new char[1024];
			while(ir.read(a)!=-1){
				System.out.println(new String(a));
			}
			OutputStream os=socket.getOutputStream();
			OutputStreamWriter osw=new OutputStreamWriter(os);
			osw.write("i am received");
			osw.flush();
			socket.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}

}
